package com.ruoyi.web.controller.decision;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.decision.domain.LaunchDecision;
import com.ruoyi.decision.service.ILaunchDecisionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 发起与决策Controller
 * 
 * @author beefcake
 * @date 2021-10-22
 */
@RestController
@RequestMapping("/decision/decide")
public class LaunchDecisionController extends BaseController
{
    @Autowired
    private ILaunchDecisionService launchDecisionService;

    /**
     * 查询发起与决策列表
     */
    @PreAuthorize("@ss.hasPermi('decision:decide:list')")
    @GetMapping("/list")
    public TableDataInfo list(LaunchDecision launchDecision)
    {
        startPage();
        List<LaunchDecision> list = launchDecisionService.selectLaunchDecisionList(launchDecision);
        return getDataTable(list);
    }

    /**
     * 导出发起与决策列表
     */
    @PreAuthorize("@ss.hasPermi('decision:decide:export')")
    @Log(title = "发起与决策", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LaunchDecision launchDecision)
    {
        List<LaunchDecision> list = launchDecisionService.selectLaunchDecisionList(launchDecision);
        ExcelUtil<LaunchDecision> util = new ExcelUtil<LaunchDecision>(LaunchDecision.class);
        return util.exportExcel(list, "发起与决策数据");
    }

    /**
     * 获取发起与决策详细信息
     */
    @PreAuthorize("@ss.hasPermi('decision:decide:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(launchDecisionService.selectLaunchDecisionById(id));
    }

    /**
     * 新增发起与决策
     */
    @PreAuthorize("@ss.hasPermi('decision:decide:add')")
    @Log(title = "发起与决策", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LaunchDecision launchDecision)
    {
        return toAjax(launchDecisionService.insertLaunchDecision(launchDecision));
    }

    /**
     * 修改发起与决策
     */
    @PreAuthorize("@ss.hasPermi('decision:decide:edit')")
    @Log(title = "发起与决策", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LaunchDecision launchDecision)
    {
        return toAjax(launchDecisionService.updateLaunchDecision(launchDecision));
    }

    /**
     * 删除发起与决策
     */
    @PreAuthorize("@ss.hasPermi('decision:decide:remove')")
    @Log(title = "发起与决策", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(launchDecisionService.deleteLaunchDecisionByIds(ids));
    }
}
